package model

import (
	"gorm.io/gorm"
	"time"
)

// 会话成员表
type ImConversationMember struct {
	Id             uint      `gorm:"column:id;type:bigint UNSIGNED;comment:主键id;primaryKey;not null;" json:"id"`                    // 主键id
	ConversationId string    `gorm:"column:conversation_id;type:varchar(60);comment:会话id;default:NULL;" json:"conversation_id"`     // 会话id
	UserId         uint      `gorm:"column:user_id;type:bigint UNSIGNED;comment:用户id;default:NULL;" json:"user_id"`                 // 用户id
	JoinedAt       time.Time `gorm:"column:joined_at;type:datetime(3);comment:加入时间;default:CURRENT_TIMESTAMP(3);" json:"joined_at"` // 加入时间
	CreatedAt      time.Time `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt      time.Time `gorm:"column:updated_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
}

// 设置与数据库的映射
func (icm *ImConversationMember) TableName() string {
	return "im_conversation_member"
}

// 添加会话成员
func (icm *ImConversationMember) Create(db *gorm.DB) error {
	return db.Create(&icm).Error
}
